import {createRouter, createWebHistory} from 'vue-router'

/*
* - 成绩管理
*   - 成绩查询
*   - 成绩录入
* - 教学管理
*   - 班级管理
*   - 课程管理
*   - 考试管理
* - 人员管理
*   - 学生信息管理
*   - 教师信息管理
*   - 教务员信息管理
* */

const routes = [
    { path: '/login', name: '登录', component: () => import('../views/Login.vue') },
    { path: '/404', name: '404 Not Found', component: () => import('../views/404NotFound.vue') },
    { path: '/', name: '系统首页', component: () => import('../views/Home.vue')},
    { path: '/affair/score/query', name: '成绩查询', component: () => import('../views/ScoreQuery.vue')},
    { path: '/affair/score/entry', name: '成绩录入', component: () => import('../views/ScoreEntry.vue')},
    { path: '/affair/class', name: '班级管理', component: () => import('../views/ClassManagement.vue')},
    { path: '/affair/course', name: '课程管理', component: () => import('../views/CourseManagement.vue')},
    { path: '/affair/exam', name: '考试管理', component: () => import('../views/ExamManagement.vue')},
    { path: '/personnel/student', name: '学生信息管理', component: () => import('../views/StudentManagement.vue')},
    { path: '/personnel/teacher', name: '教师信息管理', component: () => import('../views/TeacherManagement.vue')},
    { path: '/personnel/staff', name: '教务员信息管理', component: () => import('../views/StaffManagement.vue')}
]

const router = createRouter(
    {
        history: createWebHistory(),
        routes
    }
)

router.beforeEach((to, _from,  next) => {
    if (sessionStorage.getItem("token")) {
        to.path === "/login" ? next("/") : next()
    } else {
        to.path === "/login" ? next() : next("/login")
    }
})

export default router
